package controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import pojo.User;

import service.GroupService;
import service.UserService;

@Controller
public class HeadController {

	@Autowired
	@Qualifier("UserService")
	private UserService userService;

	@RequestMapping(value = "/logout.do")
	private String logout(HttpSession session) {
		User user = (User) session.getAttribute("user");
		if (user != null) {
			session.removeAttribute("user");
			this.userService.logout(user.getId(), 0);
		}
		if (session.getAttribute("referee") != null) {
			session.removeAttribute("referee");
		}
		if (session.getAttribute("admin") != null) {
			session.removeAttribute("admin");
		}
		return "redirect:/toLogin";
	}
}
